const baseUrl = "http://192.168.1.14:8181/";

export default function request(url, methodOrData, data = {}) {

	let method = "GET";
	if (typeof methodOrData === 'string') {
		method = methodOrData; // 第二个参数是 method
	} else {
		data = methodOrData; // 第二个参数是 data
	}

	return new Promise((resolve, reject) => {
		if (method == 'FILE' || method == 'file' || method == 'File') {
			uni.uploadFile({
				url: baseUrl + url,
				filePath: data,
				name: 'file',
				success: (res) => {
					resolve(JSON.parse(res.data));
				},
				fail: (err) => {
					reject(err);
				}
			});
		} else {
			uni.request({
				url: baseUrl + url,
				method: method,
				data: data,
				success: (res) => {
					resolve(res.data);
				},
				fail: (err) => {
					reject(err);
				}
			});
		}
	});
}